package 牛客.二分查找_排序;

public class BM17二分查找_I {
    public int search (int[] nums, int target) {
        // write code here
        int left=0;
        int right=nums.length-1;

        int mid=0;
        while (left<=right) {
            //mid=(right+left)/2;
            mid=((right-left)>>1)+left;
            if (nums[mid]<target) {
                left=mid+1;
            }else if (nums[mid]>target) {
                right=mid-1;
            }else {
                return mid;
            }

        }
        return -1;

    }
}
